package com.huluobo.higt4demo1911.core.http.call;

import org.greenrobot.greendao.annotation.NotNull;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by lc on 2022/4/21.
 * 1.封装了Observer,为了让外部调用时可以少方法的调用
 * 2.处理公共code,为其他状态码提供分支
 */
public abstract class CallObserver<T> implements Observer<DataBean<T>>, IObserver<T> {

    @Override
    public void onSubscribe(@NotNull Disposable d) {

    }

    @Override
    public void onNext(@NotNull DataBean<T> tDataBean) {
        //处理公共code
        switch (tDataBean.code) {
            default:
            case 0:
                success(tDataBean.data);
                break;
        }
    }

    @Override
    public void onError(@NotNull Throwable e) {
        fail(e.getMessage());
    }

    @Override
    public void onComplete() {

    }
}
